#!/usr/bin/env python
#coding: utf-8
# redis 模块
import redis,time

class RedisHelper:
	def __init__(self):
		self.__conn = redis.Redis(host='127.0.0.1')

	def get(self,key):
		return self.__conn.get(key)

	def set(self,key,value):
		self.__conn.set(key,value)

	def set_ex(self,key,value,ex):
		self.__conn.set(key,value,ex)

	def public(self,msg,channel):
		self.__conn.publish(channel,msg)

	def subscribe(self,channel):
		pub = self.__conn.pubsub()
		pub.subscribe(channel)
		pub.parse_response()
		return pub

if  __name__ == '__main__':
	redis_cli = RedisHelper()

	while True:
		data = raw_input('input:') 
		redis_cli.public(data)

# #redis_cli.set('k1','chobit')
# redis_cli.set_ex('k1','chobit',5)
# print redis_cli.get('k1')
# print redis_cli.get('k1')
# print redis_cli.get('k1')
# print redis_cli.get('k1')
# print redis_cli.get('k1')
# time.sleep(6)
# print redis_cli.get('k1')